<template>
	<view class="content">
		<button class="size" @tap="compressImage">图片压缩转换</button>
		<image :src="src"></image>
		<button class="size" @tap="compressVideo">视频压缩</button>
		<video id="myVideo" :src="current.src" autoplay></video>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: "",
				current: {
					src: '',
				},
			}
		},
		methods: {
			compressImage() {
				var that = this;
				uni.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					success: res => {
						console.log(res);
						plus.zip.compressImage({
								src: res.tempFilePaths[0],
								dst: '_doc/a.jpg',
								quality: 70, //压缩比例
								overwrite: true,
								width: '350px', //图片宽度,
								rotate: 90, //旋转90度
								clip: {
									top: "25%",
									left: "25%",
									width: "50%",
									height: "50%"
								},
								format: "png"
							},
							function(e) {
								//执行上传
								that.src = e.target;
								console.log('Compress success!', e);
							},
							function(error) {
								console.log('Compress error!', error);
							}
						);
					},
					fail: err => {
						console.log('failed', err);
					}
				});
			},
			compressVideo(){
				let that = this;
				uni.chooseVideo({
					sourceType: ['camera', 'album'],
					success: function(res) {
						console.log("res=>", res)
						let src = res.tempFilePath;
						plus.nativeUI.showWaiting();
						plus.zip.compressVideo({
							src: src,
							quality: 'medium'
						}, function(e) {
							plus.nativeUI.closeWaiting();
							that.current.src = e.tempFilePath;
							console.log("tempFilePath=>", that.current.src)
							console.log("压缩视频成功：" + JSON.stringify(e));
						}, function(e) {
							plus.nativeUI.closeWaiting();
							console.log("压缩视频失败：" + JSON.stringify(e));
						});
					}
				});
			}

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.size {
		margin: 30rpx 0;
	}
</style>
